<div class="col-md-12">
  <div class="card">
    <div class="card-header">
      <h3 class="card-title">应用诊断任务列表</h3>
    </div>
    <div class="card-body">
      <div id="idlekey-div">
        <form class="row align-items-center" role="form"  method="post" action="${request.contextPath}/manage/app/tool/diagnostic/result"
              id="appList" name="ec">
          <div class="col-auto">
            <input type="text" class="form-control" id="appId" name="appId"
                   value="${appId!}" placeholder="应用id">
          </div>
          <div class="col-auto">
            <input type="text" class="form-control" id="parentTaskId" name="parentTaskId"
                   value="${parentTaskId!}" placeholder="任务id">
          </div>
          <div class="col-auto">
            <input type="text" class="form-control" id="auditId" name="auditId"
                   value="${auditId!}" placeholder="审批id">
          </div>
          <div class="col-md-2">
            <select name="type" class="form-select w-100">
              <option value="" <#if (type == '')>selected</#if>>
              诊断类型
              </option>
              <#list diagnosticTypeMap?keys as key>
                <option value="${key!}" <#if (key == type)>selected</#if>>
                  ${diagnosticTypeMap[key]!}
                </option>
              </#list>
            </select>
          </div>

          <div class="col-md-2">
            <select name="diagnosticStatus" class="form-select w-100">
              <option value="" <#if (diagnosticStatus == '')>selected</#if>>
              诊断状态
              </option>
              <option value="0" <#if (diagnosticStatus == 0)>selected</#if>>
              诊断中
              </option>
              <option value="1" <#if (diagnosticStatus == 1)>selected</#if>>
              诊断完成
              </option>
              <option value="2" <#if (diagnosticStatus == 2)>selected</#if>>
              诊断异常
              </option>
            </select>
          </div>
          <button type="submit" class="btn btn-success">查询</button>
        </form>
      </div>

      <div class="row">
        <div class="col-md-12">
          <div class="portlet box light-grey" id="clientIndex">

            <table class="table table-striped table-bordered table-hover" id="tableDataList">
              <thead>
              <tr>
                <td>序号</td>
                <th>appId</th>
                <th>应用名称</th>
                <th>诊断类型</th>
                <th>任务id</th>
                <th>子任务id</th>
                <th>审批id</th>
                <th>节点</th>
                <th>诊断条件</th>

                <th>创建时间</th>
                <th>诊断状态</th>
                <th>诊断耗时</th>
                <th>诊断结果</th>
              </tr>
              </thead>
              <tbody>
              <#list diagnosticTaskRecordList as record>
                <#assign app_id = record.appId>
                <tr>
                  <td>${record_index + 1}</td>
                  <td>
                    <a target="_blank" href="${request.contextPath}/manage/app/index?appId=${app_id!}">${app_id!}</a>
                  </td>
                  <td>
                    <a target="_blank"
                       href="${request.contextPath}/admin/app/index?appId=${app_id!}">${appDescMap?api.get(app_id).name!}</a>
                  </td>
                  <td>
                    ${diagnosticTypeMap[record.type]!}
                  </td>
                  <td>
                    <a target="_blank" href="${request.contextPath}/manage/task/flow?taskId=${record.parentTaskId!}">
                      ${record.parentTaskId!}
                    </a>
                  </td>
                  <td>
                    <a target="_blank" href="${request.contextPath}/manage/task/flow?taskId=${record.taskId!}">
                      ${record.taskId!}
                    </a>
                  </td>
                  <td>
                    <a target="_blank"
                       href="${request.contextPath}/manage/app/auditList?auditId=${record.auditId!}">
                      ${record.auditId!}
                    </a>
                  </td>
                  <td>
                    ${record.node!}
                  </td>
                  <td>
                    ${record.diagnosticCondition!}
                  </td>
                  <td>
                    ${record.createTime?string("yyyy-MM-dd HH:mm:ss")}
                  </td>
                  <td>
                    <#if (record.status==0)>诊断中</#if>
                    <#if (record.status==1)>诊断完成</#if>
                    <#if (record.status==2)>诊断异常</#if>
                  </td>
                  <td>
                    <#if (record.status==1)>${record.formatCostTime!}</#if>
                  </td>
                  <td>
                    <#if (record.status==1) && (record.type!=4)>
                      <button type="button" class="btn btn-sm btn-info"
                              data-bs-target="#modal-diagnosticResult" data-bs-toggle="modal"
                              data-rediskey="${record.redisKey!}"
                              data-title="应用${app_id!} 节点${record.node!}">
                        查看结果
                      </button>
                    </#if>
                  </td>
                </tr>
              </#list>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>


<div id="modal-diagnosticResult" class="modal fade" tabindex="-1">
  <div class="modal-dialog" style="width: 100%">
    <div class="modal-content">

      <div class="modal-header">
        <h4 class="modal-title">
          诊断结果
          <small><label id="modal-title" style="color: #00BE67"></label></small>
        </h4>
        <button type="button" class="close" data-bs-dismiss="modal" aria-hidden="true"></button>
      </div>

      <form class="form-horizontal form-bordered form-row-stripped">
        <div class="modal-body" style="height:500px; overflow:scroll;">
          <div class="row">
            <!-- 控件开始 -->
            <div class="col-md-12">
              <table class="table table-bordered table-striped table-hover">
                <thead id="diagnosticResultCount"></thead>
                <tbody id="diagnosticResultTable"></tbody>
              </table>
            </div>
          </div>
        </div>

        <div class="modal-footer">
          <button type="button" data-bs-dismiss="modal" class="btn btn-secondary">Close</button>
        </div>
      </form>
    </div>
  </div>
</div>

</div>
</div>